﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using XemPhim;
using System.Data;
using System.Data.SqlClient;


/// <summary>
/// Summary description for DatPhimDao
/// </summary>
/// 
namespace XemPhim
{
public class DatPhimDao
{

        public DataTable  LoadMaKhachHang()
        {


            DataProvider data = new DataProvider();
            return data.ExecuteCommandText("Select * From KhachHang ");
        }

        public DataTable loadVe()
        {
            DataProvider data = new DataProvider();
            return data.ExecuteStore("loadVe");
        }

        public DataTable huyVe(int ID)
        {
            DataProvider data = new DataProvider();
            SqlParameter[] arrParam = { new SqlParameter("@maVe", SqlDbType.Int) };
            arrParam[0].Value = ID;
            return data.ExecuteStore("sp_HuyVe ", arrParam);
        }
        public DataTable huyVeFix(int ID)
        {
            DataProvider data = new DataProvider();
            SqlParameter[] arrParam = { new SqlParameter("@maVe", SqlDbType.Int) };
            arrParam[0].Value = ID;
            return data.ExecuteStore("sp_HuyVe_fixed ", arrParam);
        }

		//
		// TODO: Add constructor logic here
		//
        public DataTable LoadMaPhim()
        {
            DataProvider data = new DataProvider();
            return data.ExecuteCommandText("Select MaPhim,TenPhim From Phim ");
        }
        public DataTable LoadMaSuatChieu()
        {
            DataProvider data = new DataProvider();
            return data.ExecuteCommandText("Select MaSuatChieu,NgayChieu From SuatChieu ");
        }

        public DataTable LoadMaSuatChieutest(int MaPhim )
        {
            DataProvider data = new DataProvider();
            return data.ExecuteCommandText("Select DISTINCT MaSuatChieu, NgayChieu From SuatChieu,Phim WHERE SuatChieu.MaPhim = " + MaPhim + "");
        }
        public DataTable LoadChoNgoitest()
        {
            DataProvider data = new DataProvider();
            return data.ExecuteCommandText("Select MaChoNgoi,Ten From ChoNgoi ");
        }

        public DataTable DatVe(int maHoaDon, int maSuatChieu, int maLoaiVe, int maChoNgoi)
        { 

 
            DataProvider sql = new DataProvider();
            SqlParameter[] arrParam = {   new SqlParameter("@maHoaDon", SqlDbType.Int), 
                                          new SqlParameter("@maSuatChieu", SqlDbType.Int ),
                                          new SqlParameter("@maLoaiVe", SqlDbType.Int),           
                                          new SqlParameter("@maChoNgoi", SqlDbType.Int ),
                                         
                                      };
            arrParam[0].Value = maHoaDon;
            arrParam[1].Value = maSuatChieu;
            arrParam[2].Value = maLoaiVe;
            arrParam[3].Value = maChoNgoi;           
            return sql.ExecuteStore("sp_DatVe", arrParam);
        }

        public DataTable sp_ThemHoaDon(int @maKH, DateTime  ngayDat, int TrangThai)
        { 
            DataProvider sql = new DataProvider();
            SqlParameter[] arrParam = {   new SqlParameter("@maKH", SqlDbType.Int), 
                                          new SqlParameter("@ngayDat", SqlDbType.DateTime ),                                                 
                                          new SqlParameter("@trangThai", SqlDbType.SmallInt),
                                         
                                      };
            arrParam[0].Value = maKH;
            arrParam[1].Value = ngayDat;
            
            arrParam[2].Value = TrangThai;           
            return sql.ExecuteStore("sp_ThemHoaDon", arrParam);
        }

        //public DataTable sp_ThemHoaDon(int @maKH, DateTime ngayDat, string ngayThanhToan, int TrangThai)
        //{
        //    DataProvider sql = new DataProvider();
        //    SqlParameter[] arrParam = {   new SqlParameter("@maKH", SqlDbType.Int), 
        //                                  new SqlParameter("@ngayDat", SqlDbType.DateTime ),
        //                                  new SqlParameter("@ngayThanhToan", SqlDbType.DateTime ),           
        //                                  new SqlParameter("@trangThai", SqlDbType.SmallInt),
                                         
        //                              };
        //    arrParam[0].Value = maKH;
        //    arrParam[1].Value = ngayDat;
        //    arrParam[2].Value = ngayThanhToan;
        //    arrParam[3].Value = TrangThai;
        //    return sql.ExecuteStore("sp_ThemHoaDon", arrParam);
        //}

    
    /*
        public DataTable insertVe()
        {
            //DataProvider data = new DataProvider();
            //return data.ExecuteCommandText("Select MaChoNgoi,Ten From ChoNgoi ");
        }
     */
}
}